package com.linewell.dao;

import com.linewell.entity.CommentPoint;
import com.linewell.entity.Point;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Title: ssm2
 * @description:
 * @author: hyuhuang@linewell.com
 * @since:2018/2/12
 */
public interface PointMapper {
    @Insert("insert into point values (${pointId},${userId},2,0)")
    void insertPoint(@Param("userId") Long userId, @Param("pointId") Long pointId);

    @Select("select * from point where user_id = ${userId} and point_id = ${pointId}")
    List<Point> isExistPoint(@Param("userId") Long userId , @Param("pointId") Long pointId);

    @Update("update article set zan_num = ${newZanNum},cai_num = ${newCaiNum} where article_id =${pointId}; ")
    void updateZanOrCai(@Param("pointId") Long pointId, @Param("newZanNum") int newZanNum, @Param("newCaiNum") int newCaiNum);

    @Update("update point set  is_favor_type = ${isFavorType} where point_id =${pointId} and user_id = ${userId};")
    void updatePoint(@Param("userId") Long userId, @Param("pointId") Long pointId, @Param("isFavorType") int isFavorType);

    @Update("update point set  is_collect_type = ${isCollectType} where point_id =${pointId} and user_id = ${userId};")
    void updatePointCollect(@Param("userId") Long userId, @Param("pointId") Long pointId, @Param("isCollectType") int isCollectType);

    @Update("update article set collect_num = ${collectNum} where article_id =${pointId}; ")
    void updateCollectNum(@Param("collectNum") int collectNum,@Param("pointId") Long pointId);


    @Select("select * from point where user_id = ${userId} and point_id = ${pointId}")
    Point checkCollectType(@Param("userId") Long userId, @Param("pointId") Long pointId);


    @Select("select * from commentpoint where reply_id = ${replyId} and comment_point_id = ${userId} ")
    List<CommentPoint> checkIsCommentFavor(@Param("replyId")Long replyId, @Param("userId")Long userId);

    @Insert("insert into commentpoint values (${userId},${replyId},2)")
    void insertCommentPoint(@Param("replyId")Long replyId, @Param("userId")Long userId);

    @Update("update reply set reply_zan = ${newZanNum},reply_cai = ${newCaiNum} where reply_id =${replyId}; ")
    void updateReplyZanOrCai(@Param("replyId")Long replyId, @Param("newZanNum")int zanNum, @Param("newCaiNum")int caiNum);

    @Update("update commentpoint set  is_comment_type = ${isFavorType} where reply_id =${replyId} and comment_point_id = ${userId};")
    void updateCommentPoint(@Param("replyId")Long replyId, @Param("userId")Long userId, @Param("isFavorType")int isFavorType);

    @Insert("insert into collected values('${pointId}','${userId}')")
    void insertCollect(@Param("pointId")Long pointId, @Param("userId")Long userId);
    @Delete("delete from collected where article_id = ${pointId} AND user_id = ${userId }")
    void deleteCollect(@Param("pointId")Long pointId, @Param("userId")Long userId);
}
